/*
 * ==============================================================================
 Name		: MusicInterceptAppView.cpp
 Author		:  
 Copyrigh	: Your copyright notice
 Description	: Application view implementation
 * ==============================================================================
 */

// INCLUDE FILES
#include <aknviewappui.h>
#include <aknconsts.h>
#include <aknnotewrappers.h>
#include <stringloader.h>

#include "MusicInterceptView2.h"
#include "MusicInterceptContainer2.h"
#include "MusicIntercept.hrh"

#include <MusicIntercept_0xE8886763.rsg>

// ========================= MEMBER FUNCTIONS ==================================

// -----------------------------------------------------------------------------
// CMusicInterceptView2::CMusicInterceptView2()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CMusicInterceptView2::CMusicInterceptView2()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CMusicInterceptView2* CMusicInterceptView2::NewL()
	{
	CMusicInterceptView2* self = CMusicInterceptView2::NewLC();
	CleanupStack::Pop(self);
	return self;
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CMusicInterceptView2* CMusicInterceptView2::NewLC()
	{
	CMusicInterceptView2* self = new (ELeave) CMusicInterceptView2();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CMusicInterceptView2::ConstructL()
	{
	BaseConstructL( R_MUSICINTERCEPT_VIEW2);
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::~CMusicInterceptView2()
// Destructor.
// -----------------------------------------------------------------------------
//
CMusicInterceptView2::~CMusicInterceptView2()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::Id()
// Returns View's ID.
// -----------------------------------------------------------------------------
//
TUid CMusicInterceptView2::Id() const
	{
	return TUid::Uid(EMusicInterceptView2Id);
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::DoActivateL()
// -----------------------------------------------------------------------------
//
void CMusicInterceptView2::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
	{
	iContainer = CMusicInterceptContainer2::NewL(ClientRect());
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::DoDeactivate()
// -----------------------------------------------------------------------------
//
void CMusicInterceptView2::DoDeactivate()
	{
	if (iContainer)
		{
		AppUi()->RemoveFromStack(iContainer);
		delete iContainer;
		iContainer = NULL;
		}
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::HandleCommandL()
// Takes care of Command handling.
// -----------------------------------------------------------------------------
//
void CMusicInterceptView2::HandleCommandL(TInt aCommand)
	{
	if (aCommand == EMusicInterceptCommand1)
		{
		// Load a string from the resource file.
		HBufC* textResource = StringLoader::LoadLC(
				R_MUSICINTERCEPT_COMMAND1_TEXT);
		CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
		informationNote->ExecuteLD(*textResource);

		// Pop HBuf from CleanUpStack and Destroy it.
		CleanupStack::PopAndDestroy(textResource);

		}
	else if (aCommand == EMusicInterceptSwitchToView1)
		{
		AppUi()->ActivateLocalViewL(TUid::Uid(EMusicInterceptView1Id));
		}
	else
		{
		AppUi()->HandleCommandL(aCommand);
		}
	}

// -----------------------------------------------------------------------------
// CMusicInterceptView2::HandleSizeChange()
// Called by HandleResourceChangeL() from CMusicInterceptAppUi when layout is 
// changed.
// -----------------------------------------------------------------------------
//
void CMusicInterceptView2::HandleSizeChange(TInt aType)
	{
	if (iContainer)
		{
		iContainer->HandleResourceChange(aType);

		if (aType == KEikDynamicLayoutVariantSwitch)
			{
			TRect rect;
			AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
			iContainer->SetRect(rect);
			}
		}
	}

// End of File
